package com.joymart.compute.model;

import com.joymart.user.model.BusinessRole;
import lombok.Data;
import lombok.Getter;
import org.springframework.data.annotation.Id;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Optional;

/**
 * 订单收益
 */
@Data
public class OrderGain {

    @Id
    private String id;
    private Type type;
    private String orderId;
    private String ownerId;
    private String contributorId;
    private BigDecimal orderOriginPv;
    //数额，这里的数是积分不是金额，和大多数地方不同
    private BigDecimal amount;
    private LocalDateTime createdAt;


    public enum Type{

        AG_WHS_GAIN("批发商收益", BusinessRole.AG_WHS),
        AU_WHS_GAIN("批发商育成", BusinessRole.AU_WHS),
        AG_AGENT_GAIN("代理收益", BusinessRole.AG_AGENT),
        AU_AGENT_GAIN("代理育成收益", BusinessRole.AU_AGENT),
        MANAGER_GAIN("经理收益", BusinessRole.MANAGER),
        AG_DIRECTOR_GAIN("总监收益", BusinessRole.AG_DIRECTOR),
        AU_DIRECTOR_GAIN("董事收益", BusinessRole.AU_DIRECTOR);

        public static Optional<Type> formRole(BusinessRole businessRole){
            return Arrays.stream(Type.values())
                    .filter(type->type.getBusinessRole() == businessRole)
                    .findAny();
        }

        Type(String text, BusinessRole businessRole) {
            this.text = text;
            this.businessRole = businessRole;
        }
        @Getter
        private String text;
        @Getter
        private BusinessRole businessRole;
    }
}
